;
var ws = new WebSocket("ws:127.0.0.1:9501/socket.io?uid=25");
ws.onopen = function() {
    console.log("Websocket open");
};
ws.onmessage = function(e) {
    // Receives a message.
    console.log(e.data);
};
ws.onerror = function(e) {
    // Receives a message.
    console.log("Websocket 连接失败回调方法");
};

ws.onclose = function() {
    console.log("closed");
};

/**
 * 推送消息
 *
 * @param {String} event 事件名
 * @param {Object} data 数据
 */
function emit(event, data) {
    if (ws.readyState === 1) {
        ws.send(
            JSON.stringify({
                event,
                data,
            })
        )
    } else {
        console.error('WebSocket 连接已关闭...', this.connect)
    }
}